/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Offer;

import XML.XMLReader;
import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.Iterator;
import java.util.List;
import javax.xml.stream.XMLStreamException;

/**
 *
 * @author c10mjn
 */
public class OfferHandler implements Iterable<Offer>{
    private static OfferHandler oh = null;
    
    private final OfferList offerList;
    
    public static OfferHandler getInstance() throws FileNotFoundException,
            XMLStreamException, ParseException{
        if(oh == null){
            oh = new OfferHandler();            
        } 
        return oh;
    }
    public OfferHandler() throws FileNotFoundException,
            XMLStreamException, ParseException{
        this.offerList = new OfferList();
        
        while (XMLReader.getInstance().hasNext()) {
            Offer temp = XMLReader.getInstance().buildOffer();
            if(temp != null){
                this.offerList.addOffer(XMLReader.getInstance().buildOffer());                    
            }
        }
    }
    
    public Offer getOffer(){
        return this.offerList.getNext();
    }
    
    public boolean hasOffer(){
        return this.offerList.hasOffer();
    }

    @Override
    public Iterator<Offer> iterator() {
        return this.offerList.iterator();
    }
    
    public Integer getNoOffers(){
        return this.offerList.getNoOffers();
    }
   
    public List<Offer> getList(){
        return this.offerList.getList();
    }
    
}
